package com.huike.web.controller.system;

import com.huike.clues.service.ISysMenuService;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.core.domain.MPentity.Menu;
import com.huike.common.core.domain.entity.SysMenu;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("system/menu")
public class SysMenuController {
    @Resource
    private ISysMenuService sysMenuService;

    /**
     * 获取菜单列表
     * @param menuName
     * @param status
     */
    @GetMapping("/list")
    public AjaxResult list(String menuName, String status) {
        List<SysMenu>list=sysMenuService.list(menuName,status);
        return AjaxResult.success(list);
    }

    /**
     * 删除菜单
     * @param menuId
     * @return
     */
    @DeleteMapping("/{menuId}")
    public AjaxResult menuId(@PathVariable Long menuId){
        int i = sysMenuService.menuId(menuId);
        if (i==0){
            return AjaxResult.error("存在子菜单,不允许删除");
        }
        if (i==1){
            return AjaxResult.error("已分配,不允许删除");
        }
        return AjaxResult.success();
    }

    /**
     * 根据菜单编号获取详细信息
     * @param menuId
     * @return
     */
    @GetMapping("/{menuId}")
    public AjaxResult getMenu(@PathVariable Long menuId){
        return AjaxResult.success(sysMenuService.getById(menuId));
    }


    /**
     * 新增菜单
     * @param menu
     * @return
     */
    @PostMapping
    public AjaxResult addMenu(@RequestBody Menu menu){
        sysMenuService.addMenu(menu);
        return AjaxResult.success();
    }

    /**
     * 修改菜单
     * @param menu
     * @return
     */
    @PutMapping
    public AjaxResult updateMenu(@RequestBody Menu menu){
        sysMenuService.updateMenu(menu);
        return AjaxResult.success();
    }

    /**
     * 获取菜单下拉树列表
     * @return
     */
    @GetMapping("/treeselect")
    public AjaxResult treeselect(){
        return AjaxResult.success(sysMenuService.treeselect());
    }

    /**
     * 加载对应角色菜单列表树
     * @param roleId
     * @return
     */
    @GetMapping("roleMenuTreeselect/{roleId}")
    public AjaxResult roleMenuTreeselect(@PathVariable Long roleId){
        return AjaxResult.success(sysMenuService.roleMenuTreeselect(roleId));
    }
}
